package com.ruoyi.web.controller.fuwu;

import java.util.List;

import com.ruoyi.system.domain.Repaircar;
import com.ruoyi.system.service.IDrivingcarService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Drivingcar;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 代驾服务 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Controller
@RequestMapping("/system/drivingcar")
public class DrivingcarController extends BaseController
{
    private String prefix = "system/drivingcar";
	
	@Autowired
	private IDrivingcarService drivingcarService;
	
	@RequiresPermissions("system:drivingcar:view")
	@GetMapping()
	public String drivingcar()
	{
	    return prefix + "/drivingcar";
	}
	
	/**
	 * 查询代驾服务列表
	 */
	@RequiresPermissions("system:drivingcar:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Drivingcar drivingcar)
	{
		startPage();
        List<Drivingcar> list = drivingcarService.selectDrivingcarList(drivingcar);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出代驾服务列表
	 */
	@RequiresPermissions("system:drivingcar:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Drivingcar drivingcar)
    {
    	List<Drivingcar> list = drivingcarService.selectDrivingcarList(drivingcar);
        ExcelUtil<Drivingcar> util = new ExcelUtil<Drivingcar>(Drivingcar.class);
        return util.exportExcel(list, "drivingcar");
    }
	
	/**
	 * 新增代驾服务
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存代驾服务
	 */
	@RequiresPermissions("system:drivingcar:add")
	@Log(title = "代驾服务", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Drivingcar drivingcar)
	{		
		return toAjax(drivingcarService.insertDrivingcar(drivingcar));
	}

	/**
	 * 修改代驾服务
	 */
	@GetMapping("/edit/{drivingcarId}")
	public String edit(@PathVariable("drivingcarId") Integer drivingcarId, ModelMap mmap)
	{
		Drivingcar drivingcar = drivingcarService.selectDrivingcarById(drivingcarId);
		mmap.put("drivingcar", drivingcar);
	    return prefix + "/edit";
	}

	/**
	 * 对代驾服务时间段进行设置界面
	 * @param drivingcarId
	 * @param mmap
	 * @return
	 */
	@GetMapping("/fuwuTimne/{drivingcarId}")
	public String fuwuTimne(@PathVariable("drivingcarId") Integer drivingcarId, ModelMap mmap){
		Drivingcar drivingcar = drivingcarService.selectDrivingcarById(drivingcarId);
		mmap.put("drivingcar", drivingcar);
		return  "system/drivingcartime/add";
	}
	/**
	 * 对代驾服务时间段进行设置界面
	 * @param drivingcarId
	 * @param mmap
	 * @return
	 */
	@GetMapping("/detail/{drivingcarId}")
	public String detail(@PathVariable("drivingcarId") Integer drivingcarId, ModelMap mmap){
		Drivingcar drivingcar = drivingcarService.selectDrivingcarById(drivingcarId);
		mmap.put("drivingCars",drivingcarService.selectDrivingcarList(null));
		mmap.put("drivingcar", drivingcar);
		return  "system/drivingcartime/drivingcartime";
	}
	
	/**
	 * 修改保存代驾服务
	 */
	@RequiresPermissions("system:drivingcar:edit")
	@Log(title = "代驾服务", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Drivingcar drivingcar)
	{		
		return toAjax(drivingcarService.updateDrivingcar(drivingcar));
	}
	
	/**
	 * 删除代驾服务
	 */
	@RequiresPermissions("system:drivingcar:remove")
	@Log(title = "代驾服务", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(drivingcarService.deleteDrivingcarByIds(ids));
	}
	/**
	 * 修改代驾服务状态
	 * @param drivingcar
	 * @return
	 */
	@Log(title = "代驾服务", businessType = BusinessType.UPDATE)
	@RequiresPermissions("system:drivingcar:edit")
	@PostMapping("/changeStatus")
	@ResponseBody
	public AjaxResult changeStatus(Drivingcar drivingcar)
	{
		return toAjax(drivingcarService.updateDrivingcar(drivingcar));
	}
}
